<?php
include('rootlogin.php');
//include('../incsession.php');
session_start();


mysql_query("SET NAMES 'utf8'");
$class=$_POST['class'];
if($_POST['submit']=="submit"){
	for($i=0; $i<sizeof($class); $i++){
		$year=$_POST['year_'.$i];
		$semester=$_POST['semester_'.$i];
		$teacher=$_POST['teacher_'.$i];
		$name=$_POST['name_'.$i];
		$valid=$_POST['valid_'.$i];
		$query = "UPDATE class SET year=".$year.",
								semester='".$semester."',
								teacher='".$teacher."',
								name='".$name."',
								valid=".$valid." 
							WHERE classid=".$class[$i];
		$result = mysql_query($query,$user_con) or die('<font color="#C11B17">Error. Please go back to the previous page and try again.</font>');
		//echo $query."<br>";
		header("location: index.php");
	}
			
}
?>

<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="framestyle.css" type="text/css" media="screen">
<style type="text/css">
.year{
	width:60px;
}
.semester{
	width:110px;
}
.teacher{
	width:250px;	
}
.name{
	width:250px;	
}
.state{
	width:90px;	
}
</style>
</head>


<body>

<div id="wrapper">
<div id="title">Online Listening Comprehension Program</div>

<div id="main">
<hr/>
<div id="title2">ADD A NEW CLASS</div>
<hr/>
<br><br>
<form method = POST action="edit_class2.php" >
<table>
<tr bgcolor="CCCCCC">
<td width=60px align="center"><font color="FFFFFF">YEAR</font>
<td width=110px align="center"><font color="FFFFFF">SEMESTER</font>
<td width=250px align="center"><font color="FFFFFF">TEACHER</font>
<td width=250px align="center"><font color="FFFFFF">CLASS NAME</font>
<td width=90px align="center"><font color="FFFFFF">STATE</font>
<?php
for($i=0; $i<sizeof($class); $i++){
	$query="SELECT * FROM class WHERE classid=".$class[$i];
	//echo $query;
	$result = mysql_query($query,$user_con);
	$row = mysql_fetch_array($result);
	echo "<input type='hidden' name='class[]' value=".$class[$i].">";
	echo "<tr><td><input class='area year' type='text' name='year_".$i."' value='".$row['year']."'>
				<td><select class='area semester' name='semester_".$i."'>";
	echo "<option";
	if($row['semester']=='fall')
		echo " selected";
	echo ">fall</option><option";
	if($row['semester']=='spring')
		echo " selected";
	echo ">spring</option></select>
				<td><input class='area teacher' type='text' name='teacher_".$i."' value='".$row['teacher']."'>
				<td><input class='area name' type='text' name='name_".$i."' value='".$row['name']."'>
				<td><select class='area state' name='valid_".$i."'><option";
	if($row['valid']==1)
		echo " selected";
	echo " value=1>valid</option><option";
	if($row['valid']==0)
		echo " selected";
	echo " value=0>expired</option></select>";
}
?>

</table>
<?php
/*

*/


?>
<br>
<div class="btn_right"><input type="submit" name = "submit" value = "submit"></div>
</form>
<form method = POST action="index.php" >
<div class="btn_right"><input type="submit" name = "submit" value = "back to index"></div>
</form>
</div>
</div>
</body>

